package com.java110.mall.cart.api;

import com.alibaba.fastjson.JSONObject;
import com.java110.mall.cart.bmo.goldBusiness.ISaveGoldBusinessBMO;
import com.java110.utils.util.Assert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName GoldBuyApi
 * @Description TODO
 * @Author wuxw
 * @Date 2021/5/6 21:48
 * @Version 1.0
 * add by wuxw 2021/5/6
 **/
@RestController
@RequestMapping(value = "/goldBuy")
public class GoldBuyApi {

    @Autowired
    private ISaveGoldBusinessBMO saveGoldBusinessBMOImpl;



    /**
     * 购买金币
     *
     *  goldObj.put("orderId", orderId);
     *  goldObj.put("buyPrice", buyPrice);
     *  goldObj.put("goldCount", goldCount);
     *  goldObj.put("userId", pd.getUserId());
     *
     * @param reqJson
     * @return
     * @serviceCode /goldBuy/buy
     * @path /app/goldBuy/buy
     */
    @RequestMapping(value = "/buy", method = RequestMethod.POST)
    public ResponseEntity<String> buy(@RequestBody JSONObject reqJson) {

        Assert.hasKeyAndValue(reqJson, "orderId", "请求报文中未包含订单");
        Assert.hasKeyAndValue(reqJson, "buyPrice", "请求报文中未包含支付金额");
        Assert.hasKeyAndValue(reqJson, "goldCount", "请求报文中未包含金币数量");
        Assert.hasKeyAndValue(reqJson, "userId", "请求报文中未包含用户");

        return saveGoldBusinessBMOImpl.buy(reqJson);
    }

    /**
     * 购买优惠券
     *
     *  goldObj.put("orderId", orderId);
     *  goldObj.put("shopId", shopId);
     *  goldObj.put("poolId", poolId);
     *  goldObj.put("buyPrice", buyPrice);
     *  goldObj.put("goldCount", goldCount);
     *  goldObj.put("userId", pd.getUserId());
     *
     * @param reqJson
     * @return
     * @serviceCode /goldBuy/buy
     * @path /app/goldBuy/buy
     */
    @RequestMapping(value = "/coupon", method = RequestMethod.POST)
    public ResponseEntity<String> coupon(@RequestBody JSONObject reqJson) {

        Assert.hasKeyAndValue(reqJson, "orderId", "请求报文中未包含订单");
        Assert.hasKeyAndValue(reqJson, "shopId", "请求报文中未包含商铺Id");
        Assert.hasKeyAndValue(reqJson, "poolId", "请求报文中未包含购物券Id");
        Assert.hasKeyAndValue(reqJson, "buyPrice", "请求报文中未包含支付金额");
        Assert.hasKeyAndValue(reqJson, "goldCount", "请求报文中未包含金币数量");
        Assert.hasKeyAndValue(reqJson, "userId", "请求报文中未包含用户");

        return saveGoldBusinessBMOImpl.coupon(reqJson);
    }
}
